{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-12-06T01:41:40.321181Z",
     "start_time": "2018-12-06T01:41:15.207339Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "L==H\n",
      "L==H\n",
      "L==H\n",
      "L==H\n",
      "iter: 0 i:4, pairs changed 1\n",
      "j is not moving enough\n",
      "iter: 0 i:7, pairs changed 2\n",
      "L==H\n",
      "L==H\n",
      "L==H\n",
      "iter: 0 i:17, pairs changed 3\n",
      "j is not moving enough\n",
      "iter: 0 i:36, pairs changed 4\n",
      "L==H\n",
      "j is not moving enough\n",
      "L==H\n",
      "L==H\n",
      "j is not moving enough\n",
      "L==H\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "L==H\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "L==H\n",
      "iteration number: 0\n",
      "iter: 0 i:4, pairs changed 1\n",
      "j is not moving enough\n",
      "iter: 0 i:7, pairs changed 2\n",
      "j is not moving enough\n",
      "L==H\n",
      "L==H\n",
      "j is not moving enough\n",
      "iter: 0 i:23, pairs changed 3\n",
      "j is not moving enough\n",
      "L==H\n",
      "L==H\n",
      "L==H\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "L==H\n",
      "L==H\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "L==H\n",
      "L==H\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "L==H\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "L==H\n",
      "iter: 0 i:29, pairs changed 1\n",
      "iter: 0 i:35, pairs changed 2\n",
      "iter: 0 i:36, pairs changed 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "L==H\n",
      "iter: 0 i:47, pairs changed 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 0 i:62, pairs changed 5\n",
      "j is not moving enough\n",
      "L==H\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "iter: 0 i:17, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "L==H\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "L==H\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 0 i:29, pairs changed 1\n",
      "iter: 0 i:44, pairs changed 2\n",
      "L==H\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "L==H\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "L==H\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "L==H\n",
      "iter: 0 i:12, pairs changed 1\n",
      "L==H\n",
      "iter: 0 i:17, pairs changed 2\n",
      "iter: 0 i:23, pairs changed 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "L==H\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "iter: 0 i:4, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "L==H\n",
      "j is not moving enough\n",
      "L==H\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "L==H\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 0 i:70, pairs changed 2\n",
      "L==H\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "L==H\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "L==H\n",
      "j is not moving enough\n",
      "iter: 0 i:12, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "L==H\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "L==H\n",
      "L==H\n",
      "j is not moving enough\n",
      "iter: 0 i:97, pairs changed 2\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 0 i:23, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 0 i:54, pairs changed 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 0 i:17, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "iter: 0 i:0, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 0 i:52, pairs changed 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 0 i:97, pairs changed 1\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "L==H\n",
      "iter: 0 i:10, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 0 i:25, pairs changed 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "L==H\n",
      "L==H\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 0 i:54, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 0 i:55, pairs changed 1\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 0 i:29, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 0 i:55, pairs changed 2\n",
      "iter: 0 i:62, pairs changed 3\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "L==H\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 1 i:69, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 3 i:55, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 4 i:23, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 0 i:55, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 2 i:54, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 0 i:23, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 0 i:54, pairs changed 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "iter: 0 i:8, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 6\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 7\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 8\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 9\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 9 i:29, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 2 i:69, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 2 i:29, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 3 i:52, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 1 i:54, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 3 i:55, pairs changed 1\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 2 i:52, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 3 i:29, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "iter: 1 i:17, pairs changed 1\n",
      "j is not moving enough\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 5 i:52, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 6\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 6 i:54, pairs changed 1\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 6\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 7\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 8\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 9\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 10\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 11\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 11 i:52, pairs changed 1\n",
      "iter: 11 i:54, pairs changed 2\n",
      "iter: 11 i:55, pairs changed 3\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 1 i:52, pairs changed 1\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "iter: 4 i:17, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 6\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 7\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 8\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 9\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 10\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 10 i:55, pairs changed 1\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "iter: 1 i:52, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "iter: 3 i:29, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 1 i:54, pairs changed 1\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 6\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 6 i:55, pairs changed 1\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "iter: 0 i:29, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 2 i:55, pairs changed 1\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 6\n",
      "iter: 6 i:17, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "iter: 2 i:29, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 5 i:55, pairs changed 1\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "iter: 4 i:17, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "iter: 5 i:23, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 2 i:55, pairs changed 1\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 6\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 7\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 8\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 9\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 10\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 11\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 12\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 13\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 14\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 15\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 16\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 17\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 18\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 19\n",
      "j is not moving enough\n",
      "iter: 19 i:52, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 6\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 7\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 8\n",
      "j is not moving enough\n",
      "iter: 8 i:54, pairs changed 1\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 6\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 7\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 7 i:55, pairs changed 1\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 6\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 7\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 8\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 9\n",
      "iter: 9 i:17, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 6\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 7\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 8\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 9\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 10\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 11\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 12\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 13\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 14\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 15\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 16\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 17\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 18\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 19\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 20\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 21\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 21 i:55, pairs changed 1\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "iteration number: 5\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 6\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 7\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 8\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 9\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 10\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 11\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 12\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 13\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 14\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 15\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 16\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 17\n",
      "iter: 17 i:29, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 6\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 7\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 8\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 9\n",
      "iter: 9 i:17, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "iter: 5 i:29, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 3 i:55, pairs changed 1\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 6\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 7\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 8\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 9\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 10\n",
      "j is not moving enough\n",
      "iter: 10 i:52, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 6\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 7\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 8\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 9\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 10\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 11\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 12\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 13\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 14\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 15\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 16\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 17\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 18\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 19\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 20\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 21\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 22\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 23\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 24\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 25\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 26\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 27\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 28\n",
      "iter: 28 i:17, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 6\n",
      "j is not moving enough\n",
      "iter: 6 i:52, pairs changed 1\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 6\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 7\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 8\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 8 i:54, pairs changed 1\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 6\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 7\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 8\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 9\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 10\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 11\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 12\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 13\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 14\n",
      "iter: 14 i:17, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 6\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 7\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 8\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 9\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 10\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 11\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 12\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 13\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 14\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 15\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 16\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 17\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 18\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 19\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 20\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 21\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 22\n",
      "j is not moving enough\n",
      "iter: 22 i:52, pairs changed 1\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 5 i:55, pairs changed 1\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "L==H\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "L==H\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "L==H\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "j is not moving enough\n",
      "iter: 5 i:23, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "iter: 0 i:17, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 6\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 6 i:54, pairs changed 1\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 6\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 7\n",
      "iter: 7 i:17, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 6\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 7\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 8\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 9\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 10\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 11\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 12\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 13\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 14\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 15\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 16\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 17\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 18\n",
      "j is not moving enough\n",
      "iter: 18 i:52, pairs changed 1\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "iter: 2 i:29, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 1 i:55, pairs changed 1\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 2 i:52, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 6\n",
      "j is not moving enough\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 7\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 8\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 9\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 10\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 11\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 12\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 13\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 14\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 15\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 16\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 17\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 18\n",
      "j is not moving enough\n",
      "iter: 18 i:54, pairs changed 1\n",
      "iter: 18 i:55, pairs changed 2\n",
      "iteration number: 0\n",
      "L==H\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "L==H\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 2 i:54, pairs changed 1\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 6\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 7\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 8\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 9\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 10\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 11\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 12\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 13\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 14\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 15\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 16\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 17\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 18\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 19\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 20\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 21\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 22\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 23\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 24\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 24 i:55, pairs changed 1\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 6\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 7\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 8\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 9\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 10\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 10 i:54, pairs changed 1\n",
      "iter: 10 i:55, pairs changed 2\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 3 i:54, pairs changed 1\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 6\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 7\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 8\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 9\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 10\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 11\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 12\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 12 i:55, pairs changed 1\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 6\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 7\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 8\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 9\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 10\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 11\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 12\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 13\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 14\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 15\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 16\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 17\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 18\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 19\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 19 i:52, pairs changed 1\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "L==H\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "L==H\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "L==H\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "L==H\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 6\n",
      "j is not moving enough\n",
      "L==H\n",
      "j is not moving enough\n",
      "iteration number: 7\n",
      "j is not moving enough\n",
      "L==H\n",
      "j is not moving enough\n",
      "iteration number: 8\n",
      "j is not moving enough\n",
      "L==H\n",
      "j is not moving enough\n",
      "iteration number: 9\n",
      "j is not moving enough\n",
      "iter: 9 i:23, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "iter: 3 i:17, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 3 i:54, pairs changed 2\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "iter: 5 i:17, pairs changed 1\n",
      "j is not moving enough\n",
      "iter: 5 i:29, pairs changed 2\n",
      "iter: 5 i:54, pairs changed 3\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 6\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 6 i:55, pairs changed 1\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 1 i:29, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 4 i:55, pairs changed 1\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 6\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 7\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 8\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 9\n",
      "j is not moving enough\n",
      "iter: 9 i:23, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 2 i:52, pairs changed 1\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 6\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 7\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 8\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 9\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 10\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 11\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 12\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 13\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 14\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 15\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 16\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 17\n",
      "j is not moving enough\n",
      "iter: 17 i:29, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iter: 3 i:55, pairs changed 1\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "iter: 4 i:17, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "iter: 2 i:29, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 6\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 7\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 8\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 9\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 10\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 11\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 12\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 13\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 14\n",
      "iter: 14 i:17, pairs changed 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "iter: 2 i:55, pairs changed 1\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "iter: 2 i:52, pairs changed 1\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "j is not moving enough\n",
      "iteration number: 6\n",
      "j is not moving enough\n",
      "iteration number: 7\n",
      "j is not moving enough\n",
      "iteration number: 8\n",
      "j is not moving enough\n",
      "iteration number: 9\n",
      "j is not moving enough\n",
      "iteration number: 10\n",
      "iter: 10 i:29, pairs changed 1\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "iter: 0 i:52, pairs changed 1\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 6\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 7\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 8\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 9\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 10\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 11\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 12\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 13\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 14\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 15\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 16\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 17\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 18\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 19\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 20\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 21\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 22\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 23\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 24\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 25\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 26\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 27\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 28\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 29\n",
      "iter: 29 i:29, pairs changed 1\n",
      "j is not moving enough\n",
      "iteration number: 0\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 1\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 2\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 3\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 4\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 5\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 6\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 7\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 8\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 9\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 10\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 11\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 12\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 13\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 14\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 15\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 16\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 17\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 18\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 19\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 20\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 21\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 22\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 23\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 24\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 25\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 26\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 27\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 28\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 29\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 30\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 31\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 32\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 33\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 34\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 35\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 36\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 37\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 38\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 39\n",
      "j is not moving enough\n",
      "j is not moving enough\n",
      "iteration number: 40\n"
     ]
    }
   ],
   "source": [
    "from numpy import *\n",
    "import random\n",
    "def loadDataSet(filename):\n",
    "    dataMat = []\n",
    "    labelMat = []\n",
    "    fr = open(filename)\n",
    "    for line in fr.readlines():\n",
    "        lineArr = line.strip().split('\\t')\n",
    "        dataMat.append([float(lineArr[0]), float(lineArr[1])])\n",
    "        labelMat.append(float(lineArr[2]))\n",
    "    return dataMat, labelMat\n",
    "\n",
    "#在简单版SMO中，alpha是随机选择的\n",
    "def selectJrand(i,m):\n",
    "    j=i\n",
    "    while j==i:\n",
    "        j = int(random.uniform(0,m))\n",
    "    return j\n",
    "\n",
    "#辅助函数，调整过大过小值 \n",
    "def clipAlpha(aj,H,L):\n",
    "    if aj > H:\n",
    "        aj = H\n",
    "    elif aj < L:\n",
    "        aj = L\n",
    "    return aj\n",
    "\n",
    "#简单版的SMO算法，随机选择两个alpha，若满足优化条件，则进行优化\n",
    "def smoSimple(dataMatIn, classLabels, C, tol, maxIter):\n",
    "    '''\n",
    "    dataMatIn: 输入数据集\n",
    "    classLabels: 类别标签\n",
    "    C: 常数\n",
    "    tol: 容错率\n",
    "    maxIter：最大循环数\n",
    "    '''\n",
    "    dataMatrix = mat(dataMatIn)\n",
    "    labelMat = mat(classLabels).transpose()\n",
    "    b = 0\n",
    "    m,n = shape(dataMatrix)\n",
    "    alphas = mat(zeros((m,1)))\n",
    "    iters = 0\n",
    "    #外循环\n",
    "    while iters < maxIter:\n",
    "        alphaPairChanged = 0\n",
    "        #内循环,对于每一个实例，对应的alpha为第一个alpha\n",
    "        for i in range(m):\n",
    "            #预测类别\n",
    "            fxi = float(multiply(alphas,labelMat).T * (dataMatrix*dataMatrix[i,:].T)) + b\n",
    "            #分类误差\n",
    "            Ei = fxi- float(labelMat[i])\n",
    "            #当误差和alpha的值满足优化条件时，进行优化，正负间隔均已考虑\n",
    "            if ((labelMat[i]*Ei < -tol) and (alphas[i] < C) or (labelMat[i]*Ei > tol) and (alphas[i]) > 0):\n",
    "                #因为alphas的和需要为零，所以要再选一个alpha进行优化\n",
    "                #随机选择第二个alpha\n",
    "                j = selectJrand(i,m)\n",
    "                fxj = float(multiply(alphas,labelMat).T * (dataMatrix*dataMatrix[j,:].T)) + b\n",
    "                Ej = fxj- float(labelMat[j])\n",
    "                #保存旧的alpha的值，因为python中传的是引用，所以使用copy函数分配新的内存。\n",
    "                alphaIold = alphas[i].copy()\n",
    "                alphaJold = alphas[j].copy()\n",
    "                #设置L和H的值，用于确保alpha在0到C之间\n",
    "                if labelMat[i] != labelMat[j]:\n",
    "                    L = max(0, alphas[j]-alphas[i])\n",
    "                    H = min(C, C+alphas[j]-alphas[i])\n",
    "                else:\n",
    "                    L = max(0, alphas[j]+alphas[i]-C)\n",
    "                    H = min(C, alphas[j] +alphas[i])\n",
    "                #如果L和H相等，则不做任何改变，跳出循环\n",
    "                if L == H:\n",
    "                    print('L==H')\n",
    "                    continue\n",
    "                #eta是alpha[j]的最优修改量\n",
    "                eta = 2.0 * dataMatrix[i,:] * dataMatrix[j,:].T - dataMatrix[i,:] * dataMatrix[i,:].T - dataMatrix[j,:] * dataMatrix[j,:].T\n",
    "                #如果eta不满足条件，则退出当前循环\n",
    "                if eta >= 0:\n",
    "                    print('eta>=0')\n",
    "                    continue\n",
    "                #更新alpha[j]\n",
    "                alphas[j] -= labelMat[j]*(Ei -Ej)/eta\n",
    "                #限制alpha[j]在0到C之间\n",
    "                alphas[j] = clipAlpha(alphas[j], H, L)\n",
    "                #如果alpha[j]该变量较小，则不做改变，直接退出循环，重新随机选择j\n",
    "                if abs(alphas[j]-alphaJold) < 0.00001:\n",
    "                    print('j is not moving enough')\n",
    "                    continue\n",
    "                #更新alpha[i], 与j的更新方向相反\n",
    "                alphas[i] += labelMat[j]*labelMat[i]*(alphaJold - alphas[j])\n",
    "                #计算截距\n",
    "                b1 = b - Ei - labelMat[i]*(alphas[i]-alphaIold)*dataMatrix[i,:]*dataMatrix[i,:].T - labelMat[j]*(alphas[j]-alphaJold)*dataMatrix[i,:]*dataMatrix[j,:].T\n",
    "                b2 = b - Ej - labelMat[i]*(alphas[i]-alphaIold)*dataMatrix[i,:]*dataMatrix[j,:].T - labelMat[j]*(alphas[j]-alphaJold)*dataMatrix[j,:]*dataMatrix[j,:].T\n",
    "                if alphas[i] > 0 and alphas[i] < C:\n",
    "                    b = b1\n",
    "                elif alphas[j] > 0 and alphas[j] < C:\n",
    "                    b = b2\n",
    "                else:\n",
    "                    b = (b1+b2)/2.0\n",
    "                alphaPairChanged += 1\n",
    "                print('iter: %d i:%d, pairs changed %d'%(iters, i, alphaPairChanged))\n",
    "        #如果alpha未更新过，则进行下一次迭代，知道alpha更新或达到最大迭代次数\n",
    "        if alphaPairChanged == 0:\n",
    "            iters += 1\n",
    "        else:\n",
    "            iters = 0\n",
    "        print('iteration number: %d'%iters)\n",
    "    return b, alphas\n",
    "\n",
    "#测试上述函数\n",
    "dataArr, labelArr = loadDataSet('testSet6.txt')\n",
    "b, alphas = smoSimple(dataArr, labelArr, 0.6, 0.001, 40)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-12-06T01:41:47.761650Z",
     "start_time": "2018-12-06T01:41:47.749640Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[-3.84210181]]\n",
      "[[0.1347479  0.22253378 0.01284783 0.36997671]]\n"
     ]
    }
   ],
   "source": [
    "print(b)\n",
    "print(alphas[alphas>0])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 完整版的SMO，启发式选取alpha."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-12-06T06:54:14.825863Z",
     "start_time": "2018-12-06T06:54:14.369539Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "fullSet, iter: 0 i:0, pairs changed 1\n",
      "fullSet, iter: 0 i:1, pairs changed 1\n",
      "fullSet, iter: 0 i:2, pairs changed 2\n",
      "fullSet, iter: 0 i:3, pairs changed 2\n",
      "fullSet, iter: 0 i:4, pairs changed 3\n",
      "fullSet, iter: 0 i:5, pairs changed 4\n",
      "fullSet, iter: 0 i:6, pairs changed 4\n",
      "fullSet, iter: 0 i:7, pairs changed 4\n",
      "j not moving enough\n",
      "fullSet, iter: 0 i:8, pairs changed 4\n",
      "fullSet, iter: 0 i:9, pairs changed 4\n",
      "j not moving enough\n",
      "fullSet, iter: 0 i:10, pairs changed 4\n",
      "fullSet, iter: 0 i:11, pairs changed 4\n",
      "fullSet, iter: 0 i:12, pairs changed 4\n",
      "fullSet, iter: 0 i:13, pairs changed 4\n",
      "fullSet, iter: 0 i:14, pairs changed 4\n",
      "fullSet, iter: 0 i:15, pairs changed 4\n",
      "fullSet, iter: 0 i:16, pairs changed 4\n",
      "j not moving enough\n",
      "fullSet, iter: 0 i:17, pairs changed 4\n",
      "fullSet, iter: 0 i:18, pairs changed 4\n",
      "fullSet, iter: 0 i:19, pairs changed 4\n",
      "fullSet, iter: 0 i:20, pairs changed 4\n",
      "fullSet, iter: 0 i:21, pairs changed 4\n",
      "fullSet, iter: 0 i:22, pairs changed 4\n",
      "j not moving enough\n",
      "fullSet, iter: 0 i:23, pairs changed 4\n",
      "j not moving enough\n",
      "fullSet, iter: 0 i:24, pairs changed 4\n",
      "L==H\n",
      "fullSet, iter: 0 i:25, pairs changed 4\n",
      "L==H\n",
      "fullSet, iter: 0 i:26, pairs changed 4\n",
      "fullSet, iter: 0 i:27, pairs changed 4\n",
      "fullSet, iter: 0 i:28, pairs changed 4\n",
      "fullSet, iter: 0 i:29, pairs changed 5\n",
      "fullSet, iter: 0 i:30, pairs changed 5\n",
      "fullSet, iter: 0 i:31, pairs changed 5\n",
      "fullSet, iter: 0 i:32, pairs changed 5\n",
      "fullSet, iter: 0 i:33, pairs changed 5\n",
      "fullSet, iter: 0 i:34, pairs changed 5\n",
      "fullSet, iter: 0 i:35, pairs changed 5\n",
      "fullSet, iter: 0 i:36, pairs changed 5\n",
      "fullSet, iter: 0 i:37, pairs changed 5\n",
      "fullSet, iter: 0 i:38, pairs changed 5\n",
      "fullSet, iter: 0 i:39, pairs changed 5\n",
      "fullSet, iter: 0 i:40, pairs changed 5\n",
      "fullSet, iter: 0 i:41, pairs changed 5\n",
      "fullSet, iter: 0 i:42, pairs changed 5\n",
      "fullSet, iter: 0 i:43, pairs changed 5\n",
      "fullSet, iter: 0 i:44, pairs changed 5\n",
      "fullSet, iter: 0 i:45, pairs changed 5\n",
      "L==H\n",
      "fullSet, iter: 0 i:46, pairs changed 5\n",
      "fullSet, iter: 0 i:47, pairs changed 5\n",
      "fullSet, iter: 0 i:48, pairs changed 5\n",
      "fullSet, iter: 0 i:49, pairs changed 5\n",
      "fullSet, iter: 0 i:50, pairs changed 5\n",
      "fullSet, iter: 0 i:51, pairs changed 5\n",
      "fullSet, iter: 0 i:52, pairs changed 5\n",
      "fullSet, iter: 0 i:53, pairs changed 5\n",
      "L==H\n",
      "fullSet, iter: 0 i:54, pairs changed 5\n",
      "L==H\n",
      "fullSet, iter: 0 i:55, pairs changed 5\n",
      "fullSet, iter: 0 i:56, pairs changed 5\n",
      "L==H\n",
      "fullSet, iter: 0 i:57, pairs changed 5\n",
      "fullSet, iter: 0 i:58, pairs changed 5\n",
      "fullSet, iter: 0 i:59, pairs changed 5\n",
      "fullSet, iter: 0 i:60, pairs changed 5\n",
      "fullSet, iter: 0 i:61, pairs changed 5\n",
      "fullSet, iter: 0 i:62, pairs changed 5\n",
      "fullSet, iter: 0 i:63, pairs changed 5\n",
      "fullSet, iter: 0 i:64, pairs changed 5\n",
      "fullSet, iter: 0 i:65, pairs changed 5\n",
      "fullSet, iter: 0 i:66, pairs changed 5\n",
      "fullSet, iter: 0 i:67, pairs changed 5\n",
      "fullSet, iter: 0 i:68, pairs changed 5\n",
      "L==H\n",
      "fullSet, iter: 0 i:69, pairs changed 5\n",
      "fullSet, iter: 0 i:70, pairs changed 5\n",
      "fullSet, iter: 0 i:71, pairs changed 5\n",
      "fullSet, iter: 0 i:72, pairs changed 5\n",
      "fullSet, iter: 0 i:73, pairs changed 5\n",
      "fullSet, iter: 0 i:74, pairs changed 5\n",
      "fullSet, iter: 0 i:75, pairs changed 5\n",
      "fullSet, iter: 0 i:76, pairs changed 5\n",
      "fullSet, iter: 0 i:77, pairs changed 5\n",
      "fullSet, iter: 0 i:78, pairs changed 5\n",
      "fullSet, iter: 0 i:79, pairs changed 5\n",
      "fullSet, iter: 0 i:80, pairs changed 5\n",
      "fullSet, iter: 0 i:81, pairs changed 5\n",
      "fullSet, iter: 0 i:82, pairs changed 5\n",
      "fullSet, iter: 0 i:83, pairs changed 5\n",
      "fullSet, iter: 0 i:84, pairs changed 5\n",
      "fullSet, iter: 0 i:85, pairs changed 5\n",
      "fullSet, iter: 0 i:86, pairs changed 5\n",
      "fullSet, iter: 0 i:87, pairs changed 5\n",
      "fullSet, iter: 0 i:88, pairs changed 5\n",
      "fullSet, iter: 0 i:89, pairs changed 5\n",
      "fullSet, iter: 0 i:90, pairs changed 5\n",
      "fullSet, iter: 0 i:91, pairs changed 5\n",
      "fullSet, iter: 0 i:92, pairs changed 5\n",
      "fullSet, iter: 0 i:93, pairs changed 5\n",
      "fullSet, iter: 0 i:94, pairs changed 5\n",
      "fullSet, iter: 0 i:95, pairs changed 5\n",
      "fullSet, iter: 0 i:96, pairs changed 5\n",
      "fullSet, iter: 0 i:97, pairs changed 5\n",
      "fullSet, iter: 0 i:98, pairs changed 5\n",
      "fullSet, iter: 0 i:99, pairs changed 5\n",
      "iteration number: 1\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:0, pairs changed 0\n",
      "non-bound, iter: 1 i:2, pairs changed 1\n",
      "non-bound, iter: 1 i:4, pairs changed 2\n",
      "non-bound, iter: 1 i:5, pairs changed 3\n",
      "non-bound, iter: 1 i:26, pairs changed 4\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:29, pairs changed 4\n",
      "iteration number: 2\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:0, pairs changed 0\n",
      "non-bound, iter: 2 i:4, pairs changed 1\n",
      "non-bound, iter: 2 i:23, pairs changed 2\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:26, pairs changed 2\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:29, pairs changed 2\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:54, pairs changed 2\n",
      "non-bound, iter: 2 i:55, pairs changed 2\n",
      "iteration number: 3\n",
      "j not moving enough\n",
      "non-bound, iter: 3 i:0, pairs changed 0\n",
      "non-bound, iter: 3 i:23, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 3 i:26, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 3 i:29, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 3 i:54, pairs changed 0\n",
      "non-bound, iter: 3 i:55, pairs changed 0\n",
      "iteration number: 4\n",
      "j not moving enough\n",
      "fullSet, iter: 4 i:0, pairs changed 0\n",
      "fullSet, iter: 4 i:1, pairs changed 0\n",
      "fullSet, iter: 4 i:2, pairs changed 0\n",
      "fullSet, iter: 4 i:3, pairs changed 0\n",
      "fullSet, iter: 4 i:4, pairs changed 0\n",
      "fullSet, iter: 4 i:5, pairs changed 0\n",
      "fullSet, iter: 4 i:6, pairs changed 0\n",
      "fullSet, iter: 4 i:7, pairs changed 0\n",
      "fullSet, iter: 4 i:8, pairs changed 0\n",
      "fullSet, iter: 4 i:9, pairs changed 0\n",
      "fullSet, iter: 4 i:10, pairs changed 0\n",
      "fullSet, iter: 4 i:11, pairs changed 0\n",
      "fullSet, iter: 4 i:12, pairs changed 0\n",
      "fullSet, iter: 4 i:13, pairs changed 0\n",
      "fullSet, iter: 4 i:14, pairs changed 0\n",
      "fullSet, iter: 4 i:15, pairs changed 0\n",
      "fullSet, iter: 4 i:16, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 4 i:17, pairs changed 0\n",
      "fullSet, iter: 4 i:18, pairs changed 0\n",
      "fullSet, iter: 4 i:19, pairs changed 0\n",
      "fullSet, iter: 4 i:20, pairs changed 0\n",
      "fullSet, iter: 4 i:21, pairs changed 0\n",
      "fullSet, iter: 4 i:22, pairs changed 0\n",
      "fullSet, iter: 4 i:23, pairs changed 0\n",
      "fullSet, iter: 4 i:24, pairs changed 0\n",
      "fullSet, iter: 4 i:25, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 4 i:26, pairs changed 0\n",
      "fullSet, iter: 4 i:27, pairs changed 0\n",
      "fullSet, iter: 4 i:28, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 4 i:29, pairs changed 0\n",
      "fullSet, iter: 4 i:30, pairs changed 0\n",
      "fullSet, iter: 4 i:31, pairs changed 0\n",
      "fullSet, iter: 4 i:32, pairs changed 0\n",
      "fullSet, iter: 4 i:33, pairs changed 0\n",
      "fullSet, iter: 4 i:34, pairs changed 0\n",
      "fullSet, iter: 4 i:35, pairs changed 0\n",
      "fullSet, iter: 4 i:36, pairs changed 0\n",
      "fullSet, iter: 4 i:37, pairs changed 0\n",
      "fullSet, iter: 4 i:38, pairs changed 0\n",
      "fullSet, iter: 4 i:39, pairs changed 0\n",
      "fullSet, iter: 4 i:40, pairs changed 0\n",
      "fullSet, iter: 4 i:41, pairs changed 0\n",
      "fullSet, iter: 4 i:42, pairs changed 0\n",
      "fullSet, iter: 4 i:43, pairs changed 0\n",
      "fullSet, iter: 4 i:44, pairs changed 0\n",
      "fullSet, iter: 4 i:45, pairs changed 0\n",
      "fullSet, iter: 4 i:46, pairs changed 0\n",
      "fullSet, iter: 4 i:47, pairs changed 0\n",
      "fullSet, iter: 4 i:48, pairs changed 0\n",
      "fullSet, iter: 4 i:49, pairs changed 0\n",
      "fullSet, iter: 4 i:50, pairs changed 0\n",
      "fullSet, iter: 4 i:51, pairs changed 0\n",
      "fullSet, iter: 4 i:52, pairs changed 0\n",
      "fullSet, iter: 4 i:53, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 4 i:54, pairs changed 0\n",
      "fullSet, iter: 4 i:55, pairs changed 0\n",
      "fullSet, iter: 4 i:56, pairs changed 0\n",
      "fullSet, iter: 4 i:57, pairs changed 0\n",
      "fullSet, iter: 4 i:58, pairs changed 0\n",
      "fullSet, iter: 4 i:59, pairs changed 0\n",
      "fullSet, iter: 4 i:60, pairs changed 0\n",
      "fullSet, iter: 4 i:61, pairs changed 0\n",
      "fullSet, iter: 4 i:62, pairs changed 0\n",
      "fullSet, iter: 4 i:63, pairs changed 0\n",
      "fullSet, iter: 4 i:64, pairs changed 0\n",
      "fullSet, iter: 4 i:65, pairs changed 0\n",
      "fullSet, iter: 4 i:66, pairs changed 0\n",
      "fullSet, iter: 4 i:67, pairs changed 0\n",
      "fullSet, iter: 4 i:68, pairs changed 0\n",
      "fullSet, iter: 4 i:69, pairs changed 0\n",
      "fullSet, iter: 4 i:70, pairs changed 0\n",
      "fullSet, iter: 4 i:71, pairs changed 0\n",
      "fullSet, iter: 4 i:72, pairs changed 0\n",
      "fullSet, iter: 4 i:73, pairs changed 0\n",
      "fullSet, iter: 4 i:74, pairs changed 0\n",
      "fullSet, iter: 4 i:75, pairs changed 0\n",
      "fullSet, iter: 4 i:76, pairs changed 0\n",
      "fullSet, iter: 4 i:77, pairs changed 0\n",
      "fullSet, iter: 4 i:78, pairs changed 0\n",
      "fullSet, iter: 4 i:79, pairs changed 0\n",
      "fullSet, iter: 4 i:80, pairs changed 0\n",
      "fullSet, iter: 4 i:81, pairs changed 0\n",
      "fullSet, iter: 4 i:82, pairs changed 0\n",
      "fullSet, iter: 4 i:83, pairs changed 0\n",
      "fullSet, iter: 4 i:84, pairs changed 0\n",
      "fullSet, iter: 4 i:85, pairs changed 0\n",
      "fullSet, iter: 4 i:86, pairs changed 0\n",
      "fullSet, iter: 4 i:87, pairs changed 0\n",
      "fullSet, iter: 4 i:88, pairs changed 0\n",
      "fullSet, iter: 4 i:89, pairs changed 0\n",
      "fullSet, iter: 4 i:90, pairs changed 0\n",
      "fullSet, iter: 4 i:91, pairs changed 0\n",
      "fullSet, iter: 4 i:92, pairs changed 0\n",
      "fullSet, iter: 4 i:93, pairs changed 0\n",
      "fullSet, iter: 4 i:94, pairs changed 0\n",
      "fullSet, iter: 4 i:95, pairs changed 0\n",
      "fullSet, iter: 4 i:96, pairs changed 0\n",
      "fullSet, iter: 4 i:97, pairs changed 0\n",
      "fullSet, iter: 4 i:98, pairs changed 0\n",
      "fullSet, iter: 4 i:99, pairs changed 0\n",
      "iteration number: 5\n",
      "The predicted label is:   [[-1.15654199]]\n",
      "The actual label is:  -1.0\n"
     ]
    }
   ],
   "source": [
    "#完整版SMO，启发式方法选取待更新的两个alpha\n",
    "\n",
    "#核转换函数\n",
    "def kernelTrans(X, A, kTup): #calc the kernel or transform data to a higher dimensional space\n",
    "    m,n = shape(X)\n",
    "    K = mat(zeros((m,1)))\n",
    "    if kTup[0]=='lin': K = X * A.T   #linear kernel\n",
    "    elif kTup[0]=='rbf':\n",
    "        for j in range(m):\n",
    "            deltaRow = X[j,:] - A\n",
    "            K[j] = deltaRow*deltaRow.T\n",
    "        K = exp(K/(-1*kTup[1]**2)) #divide in NumPy is element-wise not matrix like Matlab\n",
    "    else: raise NameError('Houston We Have a Problem -- \\\n",
    "    That Kernel is not recognized')\n",
    "    return K\n",
    "\n",
    "#建立一个对象，用于存储重要的中间变量\n",
    "class optStruct:\n",
    "    def __init__(self,dataMatIn, classLabels, C, toler, kTup):  # Initialize the structure with the parameters \n",
    "        self.X = dataMatIn\n",
    "        self.labelMat = classLabels\n",
    "        self.C = C\n",
    "        self.tol = toler\n",
    "        self.m = shape(dataMatIn)[0]\n",
    "        self.alphas = mat(zeros((self.m,1)))\n",
    "        self.b = 0\n",
    "        #用于缓存误差，帮助寻找最佳的第二个参数alphas[j]\n",
    "        self.eCache = mat(zeros((self.m,2))) #first column is valid flag\n",
    "        self.K = mat(zeros((self.m,self.m)))\n",
    "        for i in range(self.m):\n",
    "            self.K[:,i] = kernelTrans(self.X, self.X[i,:], kTup)\n",
    "\n",
    "#已知alpha，计算误差E，\n",
    "def calcEk(oS, k):\n",
    "    fXk = float(multiply(oS.alphas,oS.labelMat).T*oS.K[:,k] + oS.b)\n",
    "    Ek = fXk - float(oS.labelMat[k])\n",
    "    return Ek\n",
    "\n",
    "#启发式选取使得误差最大的第二个变量alpha[j]\n",
    "def selectJ(i, oS, Ei):         #this is the second choice -heurstic, and calcs Ej\n",
    "    maxK = -1; maxDeltaE = 0; Ej = 0\n",
    "    oS.eCache[i] = [1,Ei]  #set valid #choose the alpha that gives the maximum delta E\n",
    "    #找出合法的误差E值，即非零值\n",
    "    validEcacheList = nonzero(oS.eCache[:,0].A)[0]\n",
    "    #如果误差缓存中非零值存在，则找到使得误差最大的第二个变量的下标j\n",
    "    if (len(validEcacheList)) > 1:\n",
    "        for k in validEcacheList:   #loop through valid Ecache values and find the one that maximizes delta E\n",
    "            if k == i: continue #don't calc for i, waste of time\n",
    "            Ek = calcEk(oS, k)\n",
    "            deltaE = abs(Ei - Ek)\n",
    "            if (deltaE > maxDeltaE):\n",
    "                maxK = k; maxDeltaE = deltaE; Ej = Ek\n",
    "        return maxK, Ej\n",
    "    #若是第一次运行，则误差缓存中为空，只能先随机选取alpha[j]\n",
    "    else:   #in this case (first time around) we don't have any valid eCache values\n",
    "        j = selectJrand(i, oS.m)\n",
    "        Ej = calcEk(oS, j)\n",
    "    return j, Ej\n",
    "\n",
    "#更新误差并存入缓存\n",
    "def updateEk(oS, k):#after any alpha has changed update the new value in the cache\n",
    "    Ek = calcEk(oS, k)\n",
    "    oS.eCache[k] = [1,Ek]\n",
    "\n",
    "#内循环，选择第二个alpha[j]并更新所选的两个变量\n",
    "#大体上和simpleSMO内循环类似，只是选择alpha[j]时使用启发式方法，而不是随机选择。此外，更新alpha后，会将其对应的误差存入缓存，用作以后使用。\n",
    "#这里使用了核函数\n",
    "def innerL(i, oS):\n",
    "    Ei = calcEk(oS, i)\n",
    "    if ((oS.labelMat[i]*Ei < -oS.tol) and (oS.alphas[i] < oS.C)) or ((oS.labelMat[i]*Ei > oS.tol) and (oS.alphas[i] > 0)):\n",
    "        #启发式选择alpha[j]\n",
    "        j,Ej = selectJ(i, oS, Ei) #this has been changed from selectJrand\n",
    "        alphaIold = oS.alphas[i].copy(); alphaJold = oS.alphas[j].copy();\n",
    "        if (oS.labelMat[i] != oS.labelMat[j]):\n",
    "            L = max(0, oS.alphas[j] - oS.alphas[i])\n",
    "            H = min(oS.C, oS.C + oS.alphas[j] - oS.alphas[i])\n",
    "        else:\n",
    "            L = max(0, oS.alphas[j] + oS.alphas[i] - oS.C)\n",
    "            H = min(oS.C, oS.alphas[j] + oS.alphas[i])\n",
    "        if L==H: print (\"L==H\"); return 0\n",
    "        eta = 2.0 * oS.K[i,j] - oS.K[i,i] - oS.K[j,j] #changed for kernel\n",
    "        if eta >= 0: print (\"eta>=0\"); return 0\n",
    "        oS.alphas[j] -= oS.labelMat[j]*(Ei - Ej)/eta\n",
    "        oS.alphas[j] = clipAlpha(oS.alphas[j],H,L)\n",
    "        #更新alpha后，将对应的误差存入缓存\n",
    "        updateEk(oS, j) #added this for the Ecache\n",
    "        if (abs(oS.alphas[j] - alphaJold) < 0.00001): print (\"j not moving enough\"); return 0\n",
    "        oS.alphas[i] += oS.labelMat[j]*oS.labelMat[i]*(alphaJold - oS.alphas[j])#update i by the same amount as j\n",
    "        #更新alpha后，将对应的误差存入缓存\n",
    "        updateEk(oS, i) #added this for the Ecache                    #the update is in the oppostie direction\n",
    "        b1 = oS.b - Ei- oS.labelMat[i]*(oS.alphas[i]-alphaIold)*oS.K[i,i] - oS.labelMat[j]*(oS.alphas[j]-alphaJold)*oS.K[i,j]\n",
    "        b2 = oS.b - Ej- oS.labelMat[i]*(oS.alphas[i]-alphaIold)*oS.K[i,j]- oS.labelMat[j]*(oS.alphas[j]-alphaJold)*oS.K[j,j]\n",
    "        if (0 < oS.alphas[i]) and (oS.C > oS.alphas[i]): oS.b = b1\n",
    "        elif (0 < oS.alphas[j]) and (oS.C > oS.alphas[j]): oS.b = b2\n",
    "        else: oS.b = (b1 + b2)/2.0\n",
    "        return 1\n",
    "    else: return 0\n",
    "\n",
    "#外循环\n",
    "def smoP(dataMatIn, classLabels, C, toler, maxIter,kTup=('lin', 0)):    #full Platt SMO\n",
    "    oS = optStruct(mat(dataMatIn),mat(classLabels).transpose(),C,toler, kTup)\n",
    "    iter = 0\n",
    "    entireSet = True; alphaPairsChanged = 0\n",
    "    while (iter < maxIter) and ((alphaPairsChanged > 0) or (entireSet)):\n",
    "        alphaPairsChanged = 0\n",
    "        #遍历整个数据集对应的alpha[i]\n",
    "        if entireSet:   #go over all\n",
    "            for i in range(oS.m):        \n",
    "                alphaPairsChanged += innerL(i,oS)\n",
    "                print (\"fullSet, iter: %d i:%d, pairs changed %d\" % (iter,i,alphaPairsChanged))\n",
    "            iter += 1\n",
    "        #仅遍历不在边界上的alpha[i],即大于0小于C\n",
    "        else:#go over non-bound (railed) alphas\n",
    "            nonBoundIs = nonzero((oS.alphas.A > 0) * (oS.alphas.A < C))[0]\n",
    "            for i in nonBoundIs:\n",
    "                alphaPairsChanged += innerL(i,oS)\n",
    "                print (\"non-bound, iter: %d i:%d, pairs changed %d\" % (iter,i,alphaPairsChanged))\n",
    "            iter += 1\n",
    "        if entireSet: entireSet = False #toggle entire set loop\n",
    "        elif (alphaPairsChanged == 0): entireSet = True  \n",
    "        print (\"iteration number: %d\" % iter)\n",
    "    return oS.b,oS.alphas\n",
    "\n",
    "#用alpha计算w\n",
    "def calcWs(alphas,dataArr,classLabels):\n",
    "    X = mat(dataArr); labelMat = mat(classLabels).transpose()\n",
    "    m,n = shape(X)\n",
    "    w = zeros((n,1))\n",
    "    #虽然遍历了整个数据集，但是只有支持向量发挥了作用，只有支持向量的alpha不为0\n",
    "    for i in range(m):\n",
    "        w += multiply(alphas[i]*labelMat[i],X[i,:].T)\n",
    "    return w\n",
    "\n",
    "#测试一下数据\n",
    "dataArr, labelArr = loadDataSet('testSet6.txt')\n",
    "b, alphas = smoP(dataArr,labelArr,0.6,0.001,40)\n",
    "dataMat = mat(dataArr)\n",
    "ws = calcWs(alphas,dataArr,labelArr)\n",
    "print('The predicted label is:  ',dataMat[0]*mat(ws)+b)\n",
    "print('The actual label is: ', labelArr[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.5"
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
